package com.eastfair.home.controller;

import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.auth.dto.UserAccountDto;
import com.eastfair.builder.dto.RemoveBuilderServiceProviderRoleDTO;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.home.dto.BindHomeServiceProviderRoleDTO;
import com.eastfair.home.dto.RemoveHomeServiceProviderRoleDTO;
import com.eastfair.home.service.HomeRegisterService;
import com.eastfair.home.vo.HomeRegisterDataVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * 主场服务用户注册
 * </p>
 *
 * @author lyw
 * @date 2022-08-10
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/homeRegister")
@Api(value = "homeRegister", tags = "主场服务用户注册")
public class HomeRegisterController {
    @Autowired
    private HomeRegisterService homeRegisterService;


    /**
     * 主场服务商注册
     *
     * @param userAccountDto 用户新增实体
     * @return
     */
    @ApiOperation(value = "主场服务商注册", notes = "主场服务商注册")
    @SysLog("注册主场服务商")
    @PostMapping("/registerHomeUser")
    public R<HomeRegisterDataVO> registerHomeUser(@RequestBody UserAccountDto userAccountDto) {
        try {
            return R.success(homeRegisterService.registerHomeUser(userAccountDto));
        } catch (BizException e) {
            return R.fail(e);
        }
    }

    /**
     * 主场服务商绑定角色.
     * @param bindHomeServiceProviderRoleDTO
     * @return
     */
   @PostMapping("/bind/homeRole")
    public R<Boolean> bindHomeServiceProviderRole(@RequestBody BindHomeServiceProviderRoleDTO bindHomeServiceProviderRoleDTO){
       try {
           return R.success(homeRegisterService.bindHomeServiceProviderRole(bindHomeServiceProviderRoleDTO));
       } catch (BizException e) {
           return R.fail(e);
       }
    }


    /**
     * 主场服务商移除角色
     * @param removeHomeServiceProviderRoleDTOList
     * @return
     */
    @PostMapping("/remove/homeRole")
    public R<Boolean> removeHomeServiceProviderRole(@RequestBody List<RemoveHomeServiceProviderRoleDTO> removeHomeServiceProviderRoleDTOList){

        try {
            return R.success(homeRegisterService.removeHomeServiceProviderRole(removeHomeServiceProviderRoleDTOList));
        } catch (BizException e) {
            return R.fail(e);
        }

    }
}
